<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    okText="确认"  cancelText="取消"
  >
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item>
                <a-input placeholder="课程号" v-model="queryParam.kch"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item>
                <a-input placeholder="课程名称" v-model="queryParam.kcmc"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="7" :md="8" :sm="24">
              <a-form-item>
                <a-select v-model="queryParam.specid" placeholder="专业组">
                  <a-select-option v-for="item in specs" :key="item.id" :value="item.id">
                    {{ item.zymc }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="7" :lg="7" :md="8" :sm="24">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
                <!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
                <!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
                <!--              </a>-->
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <!-- table区域-begin -->
      <div>
        <a-table
          ref="table"
          size="middle"
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          @change="handleTableChange"
        >
          <template slot="htmlSlot" slot-scope="text">
            <div v-html="text"></div>
          </template>
          <template slot="imgSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px; font-style: italic">无此图片</span>
            <img
              v-else
              :src="getImgView(text)"
              height="25px"
              alt="图片不存在"
              style="max-width: 80px; font-size: 12px; font-style: italic"
            />
          </template>
          <template slot="fileSlot" slot-scope="text">
            <span v-if="!text" style="font-size: 12px; font-style: italic">无此文件</span>
            <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="uploadFile(text)">
              下载
            </a-button>
          </template>
          <span slot="action" slot-scope="text, record">
            <a @click="handleDetail(record)">详情</a>
          </span>
          <span slot="radio" style="padding-left: 10px" slot-scope="text, record">
            <a-radio @click="targetModel = record" :checked="targetModel.id == record.id"></a-radio>
          </span>
        </a-table>
      </div>
    </a-card>
  </a-modal>
</template>

<script>
import '@/assets/scss/common.scss';
import { EduListMixin } from '@/mixins/EduListMixin'
import { httpAction } from '@/api/common/manage'

import { formatDate } from '@/utils/util'

export default {
  name: 'JwJiaocaiSelectCourse',
  mixins: [EduListMixin],
  components: {},
  data() {
    return {
      confirmLoading: false,
      eduurl: window._CONFIG['domianBaseURL'],
      id: '09d5e1e7f9b049008eee645c783a1d67',
      title: '选择课程',
      width: '80%',
      visible: false,
      targetModel: {},
      ids: '',
      // 表头
      columns: [
        {
          title: '',
          dataIndex: '',
          key: 'id',
          width: 50,
          align: 'center',
          scopedSlots: { customRender: 'radio' },
        },
        {
          title: '课程号',
          align: 'center',
          dataIndex: 'kch',
        },
        {
          title: '课程名称',
          align: 'center',
          dataIndex: 'kcmc',
        },

        // {
        //   title: '专业',
        //   align: 'center',
        //   dataIndex: 'specid',
        // },

        ,
      ],
      url: {
        list: '/jxzy/jwKecheng/list',
      },
      dictOptions: {},
      isorter: [],
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  created() {
    this.getDeps()
  },
  methods: {
    initDictConfig() {},
    handleCancel() {
      this.close()
    },
    close() {
      this.visible = false
    },
    handleOk() {
      if (this.targetModel.id == null) {
        this.$message.warning('未选择课程')
        return
      }

      //回送所选教材信息
      this.$emit('ok', this.targetModel, this.targetModel.id)
      this.close()
    },
    show(ids) {
      this.visible = true
      this.searchQuery()

      this.targetModel = {}
    },
    getDeps() {
      var getSpecUrl = this.eduurl + '/common/veCommon/querySpecialtyListByFalId'
	   httpAction(getSpecUrl, { falId: '001', id: this.id }, 'get').then((res) => {
          if (res.success) {
            this.specs = res.result
            console.log(this.specs)
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
  },
}
</script>
